////////////////////////////////////////////////////////////////////////////////
// Filename: queue.cpp
////////////////////////////////////////////////////////////////////////////////
#include "queue.hpp"

template <class T> Queue<T>::Queue() {
	elemCount = 0;
	first = 0;
	last = 0;
}

template <class T> void Queue<T>::Empty() {
	if (first != 0) {
		while (first != 0) {
			Dequeue();
		}
	}
	last = 0;
	elemCount = 0;
}

template <class T> int Queue<T>::GetElemCount() {
	return elemCount;
}

template <class T> Elem<T>* Queue<T>::First() {
	return first;
}

template <class T> void Queue<T>::Enqueue(Elem<T>* elem) {
	if (first == 0) {
		first = elem;
		last = first;
	} else {
		last->SetNextElem(elem);
		last = elem;
	}
	++elemCount;
}

template <class T> void Queue<T>::Dequeue() {
	if (first != 0) {
		Elem<T>* elem = first->GetNextElem();
		delete first;
		first = elem;
		delete elem;
		elem = 0;
	}
}
